package cn.healthlink;
import cn.healthlink.instant.InstantTest;
import cn.healthlink.no_5.bfpp.Book;
import cn.healthlink.refresh.MyClassPathXmlApplicationContext ;
import cn.healthlink.xmlstudy.ComponentB;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author dengzhiyuan
 * @version 1.0
 * @time 2020/10/22 17:17
 */
public class MainTest {

	public static void main(String[] args) {
//		ApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring-test.xml");
//		ApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring-test.xml");
////		UserService userService = (UserService) context.getBean("userService");
////		User user = userService.getUserById("id");
////		System.out.println(user);
//		//获取User2
//		Object obj1 = context.getBean("userFactoryBean");
//		//获取UserFactoryBean
//		Object obj2 = context.getBean("&userFactoryBean");
//		System.out.println(obj1);
//		System.out.println(obj2);
		new MainTest().testLifeCycle();
	}


	private void test1(){
		ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring-bf.xml");
		ComponentB bean = applicationContext.getBean(ComponentB.class);
		System.out.println(bean.getClass());
	}

	private void testInstant(){
		ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring-instant.xml");
		InstantTest bean = applicationContext.getBean(InstantTest.class);
		System.out.println(bean.getClass());
	}

	private void testInitParam(){
		ApplicationContext applicationContext = new MyClassPathXmlApplicationContext("classpath:spring-bf.xml");
	}

	/**
	 * 测试属性转换并赋值
	 * @author dengzhiyuan
	 * @version 1.0
	 * @time 2021/2/20 11:23
	 * @param 
	 * @return 
	 */
	private void testPropertyEditor(){
		ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring-property.xml");
		User user = (User)applicationContext.getBean("user");
		System.out.println(user.toString());

	}

	/**
	 * 测试BeanFactoryPostProcessor
	 * @author dengzhiyuan
	 * @version 1.0
	 * @time 2021/2/20 11:23
	 * @param
	 * @return
	 */
	private void testBfpp(){
		ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring-bfpp.xml");
		Book book1 = (Book)applicationContext.getBean("book1");
		Book book2 = (Book)applicationContext.getBean("book2");
		System.out.println(book1.toString());
		System.out.println(book2.toString());

	}

	/**
	 * 测试生命周期
	 * @author dengzhiyuan
	 * @version 1.0
	 * @time 2021/2/20 11:23
	 * @param
	 * @return
	 */
	private void testLifeCycle(){
		ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring-lifecycle.xml");
//		applicationContext.start();

	}



}
